<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="order"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }

        .modal-body img {
            width: 100%;
        }
    </style>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">订单管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/order/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入用户名或订单编号">
                </div>
                <div class="form-group">
                    <label>订单类型:</label>
                    <select class="form-control" name="state">
                        <option value="-1">全部</option>
                        <option value="1">已加购</option>
                        <option value="2">已支付</option>
                    </select>
                </div>
                <script>
                    $("#searchForm select[name='state']").val(${(qo.state)!})
                </script>
                <button class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>商品封面</th>
                    <th>商品名称</th>
                    <th>订单用户</th>
                    <th>订单总积分</th>
                    <th>订单编号</th>
                    <th>订单状态</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${(entity.goodsCoverUrl)!}" width="80px"></td>
                        <td>${(entity.goodsName)!}</td>
                        <td>${(entity.user.nickName)!}</td>
                        <td>${(entity.totalIntegral)!}</td>
                        <td>${(entity.sn)!}</td>
                        <td>${(entity.stateName)!}</td>
                        <td>
                            <a role="button" class="btn btn-primary btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-sunglasses"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<#-- Order -->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/order/saveOrUpdate.do" enctype="multipart/form-data"
                      method="post" id="editForm">
                    <input type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="goodsName" disabled/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">订单用户：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" disabled/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">订单状态：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="state" disabled>
                                <option value="1">已加购</option>
                                <option value="2">已支付</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">订单编号：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="sn" disabled/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">订单总积分：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="totalIntegral"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        //给保存按钮和添加按钮绑定点击事件
        $(".inputBtn").click(function () {
            //先清除模态框中的内容
            $("#editForm input").val("");
            //拿到存储起来的数据
            var json = $(this).data("json");
            console.log(json);
            if (json) {
                //开始渲染数据
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='totalIntegral']").val(json.totalIntegral);
                $("#editForm input[name='sn']").val(json.sn);
                $("#editForm select[name='state']").val(json.state);
                $("#editForm input[name='name']").val(json.userNickName);
                $("#editForm input[name='goodsName']").val(json.goodsName);
            }
            if (json.state == 2) {
                $("#editForm input[name='totalIntegral']").attr("disabled", true);
            }
            $("#inputModal").modal("show");
        });
        //给提交按钮绑定事件
        $(".submitBtn").click(function () {
            $("#editForm").submit();
        })
    })
</script>
</body>
</html>